package com.zw.a.basic.a08.demo05_stringbuilder;


//案例: 演示StringBuilder和String之间的相互转换.
/*
    String对象  ->  StringBuilder对象
        public StringBuilder(String str);       带参构造, 创建StringBuilder对象.

    StringBuilder对象  ->  String对象
        StringBuilder类中的toString()方法
            public String toString();          返回该对象的字符串形式.
 */
public class Demo03 {
    public static void main(String[] args) {
        //1.定义空参不可变StringBuilder对象, 往里边添加完"hello"字符串后, 再将其转成String类型的对象.
        StringBuilder sb = new StringBuilder();
        sb.append("hello");
        String s1 = sb.toString();          // StringBuilder对象  ->  String对象
        System.out.println("s1: " + s1);
        System.out.println("--------------------");

        //2.将String字符串转成StringBuilder对象, 然后打印.
        String s2 = "传智播客";
        StringBuilder sb2 = new StringBuilder(s2);      //String对象  ->  StringBuilder对象
        System.out.println("sb2: " + sb2);
    }
}
